//拦截请求
import LocalStorageConstant from "@/constant/LocalStorageConstant"
import {UniRouter, UniStorage} from "@/util/uniUtils";
import RouterPath from "@/constant/RouterPath";


//拦截路由
const routerInterceptor = {
    invoke(args){
        //获取token
        let token = UniStorage.get(LocalStorageConstant.TOKEN)
        if (token){
            if (args.url === RouterPath.login.login){
                console.log("有token访问登录页跳转首页")
                UniRouter.switchTab(RouterPath.tabbar.home)
                return false
            }
            return true
        }
        // console.log("拦截到",args)
    }
}
let routerList = ["navigateTo", "redirectTo", "reLaunch", "switchTab"]
routerList.forEach(item => uni.addInterceptor(item, routerInterceptor))
